from ruamel import yaml
from config.setting import SETTINGS_YAML_PATH


class OperationYaml:
    """对settings的yaml文件进行读取或者写入操作"""
    @staticmethod
    def read_yaml():
        with open(str(SETTINGS_YAML_PATH), mode='r+', encoding='utf-8') as f:
            doc = yaml.round_trip_load(f)
            return doc

    @staticmethod
    def write_yaml(data):
        with open(str(SETTINGS_YAML_PATH), mode='a', encoding='utf-8') as f:
            doc = yaml.round_trip_dump(data, f)
            return doc

    @staticmethod
    def get_yaml(path):
        with open(str(path),mode='r+', encoding='utf-8') as f:
            doc = f.read()
            d = yaml.load(doc)
            print(d)

if __name__ == '__main__':
    path = r'E:\msshuo-test\data\single\test_apply_join.yam'
    OperationYaml.get_yaml(path)